export default {
	/**
	 * 快运计算模式 model 1
	 */
	//快运计算模式 - 运费 - 抛货计算
	referenceVolumeExpress(searchPriceData, volume) {
		let volume_price = this.getIntervalOtherPrice(
			searchPriceData.volume_interval,
			searchPriceData.volume_unit_price,
			volume
		);
		let interval_index = this.getIntervalIndex(
			searchPriceData.volume_interval,
			volume
		);
		let money = 0;
		if (interval_index != 0) {
			if (interval_index + 1 == searchPriceData.volume_interval.length) {
				money = Number(volume_price) * Number(volume);
			} else {
				money = Number(volume_price) * Number(volume);
			}
		} else {
			money = Number(volume_price);
		}
		return money;
	},
	//快运计算模式 - 运费 - 重货计算
	referenceWeightExpress(searchPriceData, weight) {
		let weight_price = this.getIntervalOtherPrice(
			searchPriceData.weight_interval,
			searchPriceData.weight_unit_price,
			weight
		);
		let interval_index = this.getIntervalIndex(
			searchPriceData.weight_interval,
			weight
		);
		let money = 0;
		if (interval_index != 0) {
			if (interval_index + 1 == searchPriceData.weight_interval.length) {
				money = Number(weight_price) * Number(weight);
			} else {
				money = Number(weight_price) * Number(weight);
			}
		} else {
			money = Number(weight_price);
		}
		console.log("weight_price----" + weight_price);
		return money;
	},
	//快运计算模式 - 运费 - 重抛货计算
	referenceWeightVolumeExpress(searchPriceData, weight, volume) {
		let weight_price = this.getIntervalOtherPrice(
			searchPriceData.weight_interval,
			searchPriceData.weight_unit_price,
			weight
		);
		let volume_price = this.getIntervalOtherPrice(
			searchPriceData.volume_interval,
			searchPriceData.volume_unit_price,
			volume
		);
		let weight_interval_index = this.getIntervalIndex(
			searchPriceData.weight_interval,
			weight
		);
		let volume_interval_index = this.getIntervalIndex(
			searchPriceData.volume_interval,
			volume
		);
		let weight_money = 0;
		let volume_money = 0;

		if (volume_interval_index != 0) {
			if (volume_interval_index + 1 == searchPriceData.volume_interval.length) {
				volume_money = Number(volume_price) * Number(volume);
			} else {
				volume_money = Number(volume_price) * Number(volume);
			}
		} else {
			volume_money = Number(volume_price);
		}

		if (weight_interval_index != 0) {
			if (weight_interval_index + 1 == searchPriceData.weight_interval.length) {
				weight_money = Number(weight_price) * Number(weight);
			} else {
				weight_money = Number(weight_price) * Number(weight);
			}
		} else {
			weight_money = Number(weight_price);
		}
		console.log("weight_price----" + weight_price);
		console.log("volume_price----" + volume_price);
		console.log("weight_money----" + weight_money);
		console.log("volume_money----" + volume_money);
		let money = 0;
		if (Number(volume_money) > Number(weight_money)) {
			money = Number(volume_money);
		} else {
			money = Number(weight_money);
		}
		return money;
	},

	/**
	 * 物流计算模式 model 2
	 */

	//物流计算模式 - 运费 - 抛货计算
	referenceVolumeLogistics(searchPriceData, volume) {
		let volume_price = this.getIntervalOtherPrice(
			searchPriceData.volume_interval,
			searchPriceData.volume_unit_price,
			volume
		);
		let interval_index = this.getIntervalIndex(
			searchPriceData.volume_interval,
			volume
		);
		let money = 0;
		if (interval_index != 0) {
			let base_price = searchPriceData.volume_unit_price[0];
			let base_volume = searchPriceData.volume_interval[1];
			let other_volume = Number(volume) - Number(base_volume);
			money = Number(base_price) + Number(volume_price) * Number(other_volume);
		} else {
			money = Number(volume_price);
		}
		return money;
	},

	//物流计算模式 - 运费 - 重货计算
	referenceWeightLogistics(searchPriceData, weight) {
		let weight_price = this.getIntervalOtherPrice(
			searchPriceData.weight_interval,
			searchPriceData.weight_unit_price,
			weight
		);
		let interval_index = this.getIntervalIndex(
			searchPriceData.weight_interval,
			weight
		);
		let money = 0;
		if (interval_index != 0) {
			let base_price = searchPriceData.weight_unit_price[0];
			let base_weight = searchPriceData.weight_interval[1];
			let other_weight = Number(weight) - Number(base_weight);
			money = Number(base_price) + Number(weight_price) * Number(other_weight);
		} else {
			money = Number(weight_price);
		}
		return money;
	},

	//物流计算模式 - 运费 - 重泡货计算
	referenceWeightVolumeLogistics(searchPriceData, weight, volume) {
		let weight_price = this.getIntervalOtherPrice(
			searchPriceData.weight_interval,
			searchPriceData.weight_unit_price,
			weight
		);
		let volume_price = this.getIntervalOtherPrice(
			searchPriceData.volume_interval,
			searchPriceData.volume_unit_price,
			volume
		);
		let weight_interval_index = this.getIntervalIndex(
			searchPriceData.weight_interval,
			weight
		);
		let volume_interval_index = this.getIntervalIndex(
			searchPriceData.volume_interval,
			volume
		);
		let weight_money = 0;
		let volume_money = 0;

		if (weight_interval_index != 0) {
			let base_price = searchPriceData.weight_unit_price[0];
			let base_weight = searchPriceData.weight_interval[1];
			let other_weight = Number(weight) - Number(base_weight);
			weight_money = Number(base_price) + Number(weight_price) * Number(other_weight);
		} else {
			weight_money = Number(weight_price);
		}

		if (volume_interval_index != 0) {
			let base_price = searchPriceData.volume_unit_price[0];
			let base_volume = searchPriceData.volume_interval[1];
			let other_volume = Number(volume) - Number(base_volume);
			volume_money = Number(base_price) + Number(volume_price) * Number(other_volume);
		} else {
			volume_money = Number(volume_price);
		}

		let money = 0;
		if (Number(volume_money) > Number(weight_money)) {
			money = Number(volume_money);
		} else {
			money = Number(weight_money);
		}
		return money;
	},

	/**
	 * 固定计算模式 model 3
	 */
	//固定计算模式 - 运费 - 抛货计算
	referenceVolumeFixed(searchPriceData, volume) {
		let volume_price = this.getIntervalOtherPrice(
			searchPriceData.volume_interval,
			searchPriceData.volume_unit_price,
			volume
		);
		let interval_index = this.getIntervalIndex(
			searchPriceData.volume_interval,
			volume
		);
		let money = 0;
		if (interval_index != 0) {
			if (interval_index + 1 == searchPriceData.volume_interval.length) {
				money = Number(volume_price) * Number(volume);
			} else {
				money = Number(volume_price);
			}
		} else {
			money = Number(volume_price);
		}
		return money;
	},

	//固定计算模式 - 运费 - 重货计算
	referenceWeightFixed(searchPriceData, weight) {
		let weight_price = this.getIntervalOtherPrice(
			searchPriceData.weight_interval,
			searchPriceData.weight_unit_price,
			weight
		);
		let interval_index = this.getIntervalIndex(
			searchPriceData.weight_interval,
			weight
		);
		let money = 0;
		if (interval_index != 0) {
			if (interval_index + 1 == searchPriceData.weight_interval.length) {
				money = Number(weight_price) * Number(weight);
			} else {
				money = Number(weight_price);
			}
		} else {
			money = Number(weight_price);
		}
		return money;
	},
	//固定计算模式 - 运费 - 重泡货计算
	referenceWeightVolumeFixed() {
		let weight_price = this.getIntervalOtherPrice(
			searchPriceData.weight_interval,
			searchPriceData.weight_unit_price,
			weight
		);
		let volume_price = this.getIntervalOtherPrice(
			searchPriceData.volume_interval,
			searchPriceData.volume_unit_price,
			volume
		);
		let weight_interval_index = this.getIntervalIndex(
			searchPriceData.weight_interval,
			weight
		);
		let volume_interval_index = this.getIntervalIndex(
			searchPriceData.volume_interval,
			volume
		);
		let weight_money = 0;
		let volume_money = 0;

		if (weight_interval_index != 0) {
			if (weight_interval_index + 1 == searchPriceData.weight_interval.length) {
				weight_money = Number(weight_price) * Number(weight);
			} else {
				weight_money = Number(weight_price);
			}
		} else {
			weight_money = Number(weight_price);
		}

		if (volume_interval_index != 0) {
			if (volume_interval_index + 1 == searchPriceData.volume_interval.length) {
				volume_money = Number(volume_price) * Number(volume);
			} else {
				volume_money = Number(volume_price);
			}
		} else {
			volume_money = Number(volume_price);
		}
		let money = 0;
		if (Number(volume_money) > Number(weight_money)) {
			money = Number(volume_money);
		} else {
			money = Number(weight_money);
		}
		return money;
	},

	//计算体积或重量区间的价格是否存在
	getWeightOrVolume(searchPriceData) {
		// 1、重量与体积价格存在 2、重量价格存在 体积价格不存在 3、重量价格不存在 体积价格存在 4、重量与体积价格不存在
		var type = 4;
		if (
			searchPriceData.weight_unit_price.length > 0 &&
			searchPriceData.volume_unit_price.length > 0
		) {
			let wprice = searchPriceData.weight_unit_price[0];
			let vprice = searchPriceData.volume_unit_price[0];
			if (Number(wprice) > 0 && Number(vprice) > 0) {
				type = 1;
			} else if (Number(wprice) > 0 && Number(vprice) <= 0) {
				type = 2;
			} else if (Number(wprice) <= 0 && Number(vprice) > 0) {
				type = 3;
			} else {
				type = 4;
			}
		} else if (
			searchPriceData.weight_unit_price.length > 0 &&
			searchPriceData.volume_unit_price.length <= 0
		) {
			let wprice = searchPriceData.weight_unit_price[0];
			if (Number(wprice) > 0) {
				type = 2;
			} else {
				type = 4;
			}
		} else if (
			searchPriceData.weight_unit_price.length <= 0 &&
			searchPriceData.volume_unit_price.length > 0
		) {
			let vprice = searchPriceData.volume_unit_price[0];
			if (Number(vprice) > 0) {
				type = 3;
			} else {
				type = 4;
			}
		} else {
			type = 4;
		}
		return type;
	},

	//重、泡货是否有价格 1抛货 0重货 2重抛货
	getWeightOrVolumePrice(goodstype, searchPriceData) {
		// 1、重量与体积价格存在 2、重量价格存在 体积价格不存在 3、重量价格不存在 体积价格存在 4、重量与体积价格不存在
		let type = this.getWeightOrVolume(searchPriceData);
		var is_price = true;
		if (goodstype == 1) {
			if (type == 1 || type == 3) {
				is_price = true;
			} else {
				is_price = false;
			}
		} else if (goodstype == 2) {
			if (type == 1) {
				is_price = true;
			} else {
				is_price = false;
			}
		} else {
			if (type == 1 || type == 2) {
				is_price = true;
			} else {
				is_price = false;
			}
		}
		return !is_price;
	},

	// 计算体积或重量区间的价格
	getIntervalOtherPrice(interval_list, unit_price, sub) {
		var interval_arr = [];
		for (let i = 0; i < interval_list.length; i++) {
			let interval = interval_list[i];
			if (Number(interval) <= sub) {
				interval_arr.push(interval);
			}
		}
		let interval_index = interval_arr.length - 1;
		console.log("interval_index----" + interval_index);
		if (interval_index < 0) {
			return 0;
		}
		let other_price = unit_price[interval_index];
		console.log(interval_arr);
		console.log(interval_list);
		console.log(unit_price);
		console.log(other_price);

		return other_price;
	},
	//   计算体积或重量区间的价格角标
	getIntervalIndex(interval_list, sub) {
		var interval_arr = [];
		for (let i = 0; i < interval_list.length; i++) {
			let interval = interval_list[i];
			if (Number(interval) <= sub) {
				interval_arr.push(interval);
			}
		}
		let interval_index = interval_arr.length - 1;
		if (interval_index < 0) {
			return 0;
		}
		return interval_index;
	},
	// 计算重泡比
	getZpb(createForm) {
		let weight = this.getTotalWeight(createForm);
		let volume = this.getTotalVolume(createForm);

		let zpb = 0;
		if (weight > 0) {
			weight = weight / 1000;
		}
		if (weight > 0 && volume > 0) {
			zpb = volume / weight;
		} else if (weight <= 0 && volume > 0) {
			zpb = 5;
		} else if (weight > 0 && volume <= 0) {
			zpb = 1;
		}
		console.log("zpb----" + zpb);
		return zpb;
	},
	// 获取总重量
	getTotalWeight(createForm) {
		let weight = 0;
		let arr = createForm.goods;
		for (let i = 0; i < arr.length; i++) {
			weight += Number(arr[i].total_weight);
		}
		console.log("total_weight----" + weight);
		return weight;
	},
	// 获取总体积
	getTotalVolume(createForm) {
		let volume = 0;
		let arr = createForm.goods;
		for (let i = 0; i < arr.length; i++) {
			volume += Number(arr[i].total_volume);
		}
		console.log("total_volume----" + volume);
		return volume;
	},
};